// packageA/pages/franchisee/account-manage/index.js
const App = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    text: '全部',
    text1: '今日',
    show: false,
    show2: false,
    deviceList:[],
    actions: [
      { name: '全部', value: '' },
      { name: '开发商', value: '3' },
      { name: '代理商', value: '2' },
      { name: '高级城市合伙', value: '0' },
      { name: '城市合伙人', value: '1' },
      { name: '个人', value: '4' }
    ],
    actions1: [
      { name: '请选择', value: '' },
      { name: '今日', value: 'today' },
      { name: '昨日', value: 'yesterday' },
      { name: '本周', value: 'this_week' },
      { name: '本月', value: 'this_month' },
      { name: '上月', value: 'last_month' }
    ],
    currentIndex: 0,
    tabs: [
      { key: 'today', title: '今日' },
      { key: 'yesterday', title: '昨日' },
      { key: 'this_week', title: '本周' },
      { key: 'this_month', title: '本月' },
      { key: 'last_month', title: '上月' }
    ],
    datetime: '',
    dayshow: false,
    show1: false,
    status:'',
    type:'today',
    totaldata:{},
    role_id:wx.getStorageSync('role_id')
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  handleShowAction() {
    this.setData({
      show: true
    })
  },
  handleShowAction2() {
    this.setData({
      show2: true
    })
  },
  onSelect(event) {
    this.setData({
      text: event.detail.name,
      status:event.detail.value
    })
    this.getList(this.data.status)
  },
  onSelect2(event) {
    this.setData({
      text1: event.detail.name,
      datetime:'',
      type:event.detail.value
    })
    this.getList(this.data.type)
    console.log(event)
    
  },
  //日历
  onDisplay() {
    this.setData({ show1: true });
  },
  onClose() {
    this.setData({ show: false });
    this.setData({ show1: false });
    this.setData({ show2: false });
  },
  onDayClick(event) {
    this.setData({
      show1: false,
      datetime: event.detail.id,
      text1:'请选择',
      type:'',
    });
    this.getList(this.data.datetime)
  },
  //今日选择
  // onSelect(event) {
  //   console.log(event.detail);
  //   this.setData({
  //     text: event.detail.name
  //   })
  // },
  dayshowbtn() {
    this.setData({ dayshow: true });
  },
  /**
 * tab切换
 */
  handleTab(e) {
    let { index, value } = e.currentTarget.dataset
    this.setData({
      currentIndex: index,
      type:value
    })
    this.getList()
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getList()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },
  getList() {
    let _this = this
    wx.showLoading({
      title: '加载中...',
    })
    App._post_form('Operation/businessAccountCenter', {
      // page: _this.data.deviceIndex,
      agent_status: _this.data.status,
      time_type: _this.data.type,
      date: _this.data.datetime,
    }, function (result) {
      wx.hideLoading()
      let Result = result.data.list
      console.log(result)
      // if (_this.data.deviceIndex == 1 && Result.length == 0) {
      //   _this.setData({
      //     deviceNoData: true,
      //     searchLoading: false,
      //     searchLoadingComplete: false
      //   })
      // }
      // if (Result.length) {
      //   _this.data.deviceTotal = result.data.count
      //   _this.data.devicePages = result.data.total_page
      //   let deviceListTemp = [];
      //   if (_this.data.deviceIndex > 1) {
      //     deviceListTemp = _this.data.deviceList.concat(Result);
      //     _this.setData({
      //       searchLoading: true, //"正在载入更多"显示
      //     });
      //   } else {
      //     deviceListTemp = Result;
      //   }
      // }
      _this.setData({
        deviceList: Result, //获取数据数组
        totaldata:result.data.total_data,
        deviceNoData: false //“没有数据”隐藏
      });
    });
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.getList()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})